# -*- coding: utf-8 -*-

#Joao Alturas_6197
#2014_10_16

import csv
import sys
import numpy as np
import xlrd
import matplotlib.pyplot as plt



from sqlalchemy import create_engine

from sqlalchemy.orm import sessionmaker

from sqlalchemy import Column, Integer, String, func

from sqlalchemy.ext.declarative import declarative_base


engine = create_engine('sqlite:///treta.db')

Base = declarative_base()

"""
#Create base dados 

"""
class Dados(Base):
	
	__tablename__ = 'dados'	
	
	id = Column(Integer, primary_key=True)						
	ano = Column(String(6))
	ipcGlobal = Column(String(20)) 	 
	varAnualTaxInfl = Column(String(20))     
	remMinMensal = Column(String(20))   
	remMaxMensal = Column(String(20)) 
	pibPercapitAnual = Column(String(20)) 
	rendNacBrutPercAnual = Column (String(20))  
	rendDispBrutPercAnual = Column (String(20))  
	remunPercapitAnual = Column (String(20)) 
	
    
	def __init__(self, ano,ipcGlobal,varAnualTaxInfl,remMinMensal,remMaxMensal,
		pibPercapitAnual,rendNacBrutPercAnual,rendDispBrutPercAnual,
                     remunPercapitAnual):
											 
			self.ano = ano
			self.ipcGlobal = ipcGlobal	 
			self.varAnual = varAnualTaxInfl
			self.remMinMensal = remMinMensal
			self.remMaxMensal= remMaxMensal
			self.pibPercapitAnual = pibPercapitAnual
			self.rendNacBrutPercAnual = rendNacBrutPercAnual
			self.rendDispBrutPercAnual = rendDispBrutPercAnual
			self.remunPercapitAnual = remunPercapitAnual
            
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()


"""
Ler dados do ficheiro

"""
xls = xlrd.open_workbook('csvFile.xls')
plan = xls.sheets()[0]
for i in xrange(plan.nrows):
        row = plan.row_values(i)
	try:
                dado = Dados(row[0], row[1],row[2], row[3], row[4], row[5], row[6], row[7], row[8])
		session.add(dado)
	except Exception, err:
		print err
session.commit()



